#ifndef CORE_TRANSLATE_H
#define CORE_TRANSLATE_H
#include "Hitable.h"
namespace RayTracer
{

	class Translate : public Hitable {
	public:
		Translate(std::shared_ptr<Hitable> p, const vec3& displacement)
			: ptr(p), offset(displacement) {}

		virtual bool Hit(
			const Ray& r, float t_min, float t_max, HitRecord& rec) const override;

		virtual bool BoundingBox(AABB& output_box) const override;

	public:
		std::shared_ptr<Hitable> ptr;
		vec3 offset;
	};

	bool Translate::Hit(const Ray& r, float t_min, float t_max, HitRecord& rec) const {
		Ray moved_r(r.origin() - offset, r.direction());
		if (!ptr->Hit(moved_r, t_min, t_max, rec))
			return false;

		rec.position += offset;
		rec.set_face_normal(moved_r, rec.normal);

		return true;
	}

	bool Translate::BoundingBox(AABB& output_box) const {
		if (!ptr->BoundingBox(output_box))
			return false;

		output_box = AABB(
			output_box.Min() + offset,
			output_box.Max() + offset);

		return true;
	}
}
#endif // !CORE_TRANSLATE_H
